Skip to content

[3.15] gh-160708: Use the type size for resized ctypes simple objects (GH-160720) - #161806

Merged
ZeroIntensity merged 1 commit into
python:3.15from
iamsaugatpandey:backport-44579b0-3.15
Nov 11, 2026
Merged

ZeroIntensity merged 1 commit into
python:3.15from
iamsaugatpandey:backport-44579b0-3.15

Conversation

@iamsaugatpandey

@iamsaugatpandey iamsaugatpandey commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

After ctypes.resize(), a simple object's buffer is larger than its
type. bool() and passing the object to a foreign function still used
the buffer size, so bool() read past a 16-byte string literal and the
call copied the whole buffer into the fixed-size PyCArgObject value,
corrupting the heap.

Use the type's size instead, like the value getter does since
gh-159739. bool() now checks the value's bytes directly, which also
covers simple types larger than 16 bytes such as c_longdouble_complex
on x86-64.
(cherry picked from commit 44579b0)

Co-authored-by: Saugat Pandey 39925335+iamsaugatpandey@users.noreply.github.com
Co-authored-by: Peter Bierma zintensitydev@gmail.com

…bjects (pythonGH-160720)

After ctypes.resize(), a simple object's buffer is larger than its
type. bool() and passing the object to a foreign function still used
the buffer size, so bool() read past a 16-byte string literal and the
call copied the whole buffer into the fixed-size PyCArgObject value,
corrupting the heap.

Use the type's size instead, like the value getter does since
pythongh-159739. bool() now checks the value's bytes directly, which also
covers simple types larger than 16 bytes such as c_longdouble_complex
on x86-64.
(cherry picked from commit 44579b0)

Co-authored-by: Saugat Pandey <39925335+iamsaugatpandey@users.noreply.github.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Copilot AI balanced review requested due to automatic review settings November 11, 2026 10:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@ZeroIntensity
ZeroIntensity merged commit f539f34 into python:3.15 Nov 11, 2026
56 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants